package com.jwthhealth_pub.old.diet.view;

import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.ProgressBar;

import com.jwthhealth_pub.R;
import com.jwthhealth_pub.common.view.TitleLayout;
import com.jwthhealth_pub.old.common.Constant;
import com.jwthhealth_pub.old.constitution.ConstitutionTypeUtil;
import com.jwthhealth_pub.old.diet.moudel.DietSecModule;
import com.jwthhealth_pub.old.diet.view.adapter.DietSecAdapter;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2016/12/27.
 */
public class DietSecActivity extends Activity {
    @BindView(R.id.rb)
    RecyclerView rv;
    @BindView(R.id.progressbar)
    ProgressBar progressBar;
    @BindView(R.id.sign_topbar)
    TitleLayout signTopbar;

    private String topid, id;
    private String title;
    private DietSecModule data;
    private DietSecAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_diet_sec);
        ButterKnife.bind(this);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }

        initData();
        initTop();
        initRecycleView();
    }

    private void initData() {
        Intent intent = getIntent();
        Bundle bundle = intent.getExtras();
        topid = bundle.getString(Constant.TOPID, "0");
        id = bundle.getString(Constant.ID, "0");
        data = (DietSecModule) bundle.getSerializable(Constant.DIETDATA);

        title = ConstitutionTypeUtil.GetDietTitle(topid, id);
    }

    private void initRecycleView() {
        rv.setLayoutManager(new LinearLayoutManager(this));
        adapter = new DietSecAdapter(topid, id, this, data.getData());
        adapter.setProgressBar(progressBar);
        rv.setAdapter(adapter);
    }

    private void initTop() {
        signTopbar.setTitle(title);
        signTopbar.setOnTitleLayoutListener(new TitleLayout.TitleLayoutListener() {
            @Override
            public void leftclick() {
                finish();
            }

            @Override
            public void leftTextClick() {

            }

            @Override
            public void rightclick() {

            }

            @Override
            public void rightTextClick() {

            }
        });
    }

    private void progressbar() {
        if (progressBar.getVisibility() == View.VISIBLE) {
            progressBar.setVisibility(View.GONE);
        } else {
            progressBar.setVisibility(View.VISIBLE);
        }
    }
}
